package com.gz.interceptor;

import javax.servlet.http.HttpSession;

import com.gz.common.model.User;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;

/**
 * 
 * 	判断是否登录
 * 
 */
public class AdminLoginInterceptor implements Interceptor{

	@Override
	public void intercept(Invocation inv) {
		
        HttpSession session = inv.getController().getSession();
        if(session!=null) {
        	User user = (User) session.getAttribute("user");
            if(user!=null) {
            	if(user.getUsergrade()>2) {
            		System.out.println("==============是否登录前置增强==============SUCCESS");
            		return;
            	}
            }
        }
        /**session为空重新登录，user为空为登录，Usergrade不大于2或者为空代表未登录*/
        System.out.println("==============是否登录前置增强==============未登录");
        inv.getController().redirect("http://localhost/api/login");
        return;
	}

}
